package com.example.logindb.sevices;

import com.example.logindb.entity.Help;
import com.example.logindb.repository.HelpRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HelpServiceImpl implements HelpService {
    private HelpRepository helpRepository;

    public HelpServiceImpl(HelpRepository helpRepository) {
        this.helpRepository = helpRepository;
    }

    @Override
    public void blindWaitforHelp(Help help) {
        helpRepository.save(help);
    }

    @Override
    public List<Help> findBlindByLoc(Double lat, Double lon) {
        Double dist= 0.5;
        Double minlat = lat - dist;
        Double maxlat = lat + dist;
        Double minlon = lon - dist;
        Double maxlon = lon + dist;
        return helpRepository.findBlindMessage(minlat,maxlat,minlon,maxlon);
    }

    @Override
    public Help findAllByAid(Integer aid) {
        return helpRepository.findAllByAid(aid);
    }

    @Override
    public void updateEnd(Help help) {
        Help help0 = helpRepository.findAllByAid(help.getAid());
        help.setVid(help0.getVid());
        help.setLon(help0.getLon());
        help.setLat(help0.getLat());
        help.setStime(help0.getStime());
        helpRepository.save(help);

    }

    @Override
    public void updateblind(Help help) {
        Help help0 = helpRepository.findAllByAid(help.getAid());
        help.setLon(help0.getLon());
        help.setLat(help0.getLat());
        help.setBid(help0.getBid());
        helpRepository.save(help);
    }

    @Override
    public List<Help> findByBid(Integer bid) {

        return helpRepository.findAllByBid(bid);

    }

    @Override
    public List<Help> findByVid(Integer vid) {
        return helpRepository.findAllByVid(vid);
    }


}